package com.ngc.mall.controller;

import com.ngc.mall.common.configure.response.ResponseResult;
import com.ngc.mall.domain.GridCategoryDomain;
import com.ngc.mall.dto.GridCategoryDTO;
import com.ngc.mall.service.IGridCategoryService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
/**
 *
 *
 * @author: chenxiaolin
 * @date 2023/8/14 22:28
**/
@RestController
@RequestMapping("/grid-category")
public class GridCategoryController {

    @Resource
    private IGridCategoryService iGridCategoryService;

    @GetMapping("/list")
    @ApiOperation("查看所有九宫格")
//    @PreAuthorize(value = "grid-category:query")
    public ResponseResult<List<GridCategoryDomain>> list(){
        return ResponseResult.success(iGridCategoryService.selectAll());
    }

    @GetMapping("/id/{id}")
    @ApiOperation("根据id查询九宫格详情")
//    @PreAuthorize(value = "grid-category:query")
    public ResponseResult<GridCategoryDomain> getDetailById(@PathVariable Long id){
        return ResponseResult.success(iGridCategoryService.getDetailById(id));
    }

    @PostMapping("")
    @ApiOperation("新增宫格")
//    @PreAuthorize(value="grid-category:add")
    public ResponseResult<Long> createGridCategory(@RequestBody GridCategoryDTO dto){
        return ResponseResult.success(iGridCategoryService.createGridCategory(dto));
    }

    @PutMapping("/id/{id}")
    @ApiOperation("根据id更新宫格")
//    @PreAuthorize(value="grid-category:edit")
    public ResponseResult<Boolean> updateGridCategory(@PathVariable Long id,@RequestBody GridCategoryDTO dto){
      return ResponseResult.auto(iGridCategoryService.updateGridCategory(dto,id));
    }

    @PutMapping("/{id}/enable")
    @ApiOperation("启用宫格")
    public ResponseResult<Boolean> updateStatusToEnabled(@PathVariable Long id){
        return ResponseResult.auto(iGridCategoryService.updateStatusById(id,true));
    }

    @PutMapping("/{id}/disable")
    @ApiOperation("停用宫格")
    public ResponseResult<Boolean> updateStatusToDisabled(@PathVariable Long id){
        return ResponseResult.auto(iGridCategoryService.updateStatusById(id,false));
    }

    @DeleteMapping("/id/{id}")
    @ApiOperation("根据id删除宫格")
    public ResponseResult<Boolean> deleteById(@PathVariable Long id){
        return ResponseResult.auto(iGridCategoryService.deleteById(id));
    }

}
